<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class WorkAttendanceRecord extends Model
{
    
    protected $table = 'work_attendance_record';
    protected $primaryKey = 'id';
    public $incrementing = true;
    protected $hidden = [];
//    protected $fillable = ['edid','eid','CurrentHumidity','CurrentTemperature','LightLux','SoilMoisture','SoilTemperature','soilEC','Time','RequestId','greenhouseName','cropName','ctime', 'mtime','dtime','gid'];
    public $timestamps = false;
    protected $guarded = [];

    public static function getList($where)
    {

        $data = DB::table('work_attendance_record as wa')
            ->orderBy('wa.id','desc');


        if(!empty($where['date']))
        {
            $data->where('wa.clock_in_date','like','%'.$where['date'].'%');
        }


        if(!empty($where['status']))
        {
            $data->where('wa.status',$where['status']);
        }
        if(!empty($where['company_id']))
        {
            $data->where('wa.company_id',$where['company_id']);
        }

        if(!empty($where['employee_id']))
        {
            $data->where('wa.employee_id',$where['employee_id']);
        }

        return $data->paginate(20);
    }


}